<template>
    <el-form :model="form" label-width="120px">
        <el-form-item label="新闻标题">
            <el-input v-model="form.title" />
        </el-form-item>
        <el-form-item label="新闻类型">
            <el-select v-model="form.category" placeholder="请选择新闻类型">
                <el-option label="经济" value="ecology" />
                <el-option label="文化" value="culture" />
                <el-option label="政治" value="politics" />
            </el-select>
        </el-form-item>
        <el-form-item label="新闻内容">
            <el-input v-model="form.content" type="textarea" />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit(form)">创建</el-button>
        </el-form-item>
    </el-form>
</template>

<script setup>
import { reactive } from 'vue';
import useNewsStore from '../store/newsStore';
import { useRouter } from 'vue-router';


const form = reactive({
    title: '',
    category: '',
    content: '',
})

const newsStore = useNewsStore()
const router = useRouter()

const onSubmit = (form) => {
    newsStore.addNews(form)

    router.push("/news/newslist")
}
</script>
